package com.tl.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 生成连续code
 * @author 15110
 *
 */
public class CodeUtil {
	
	private static final AtomicInteger atomicInteger1 = new AtomicInteger(1000);
	
	private static final AtomicInteger atomicInteger2 = new AtomicInteger(100);
	
	public static synchronized String getOrderCode(String no) {
		Integer uuidHashCode = UUID.randomUUID().toString().hashCode();
		if (uuidHashCode < 0) {
			uuidHashCode = uuidHashCode * (-1);
		}
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyMMddHHmmss");
		String date = simpleDateFormat.format(new Date());
		atomicInteger1.getAndIncrement();
		int i = atomicInteger1.get();
		return no + date + i ;
	}
	
	public static synchronized String getAppUserCode(String no) {
		Integer uuidHashCode = UUID.randomUUID().toString().hashCode();
		if (uuidHashCode < 0) {
			uuidHashCode = uuidHashCode * (-1);
		}
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyMMddHHmm");
		String date = simpleDateFormat.format(new Date());
		atomicInteger2.getAndIncrement();
		int i = atomicInteger2.get();
		return no + date + i ;
	}
	
	public static void main(String[] args) {
		System.out.println(getAppUserCode(""));
	}
}
